/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.KDniao.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.KDniao.entity.LogisticTrackingTrajectory;
import com.thinkgem.jeesite.modules.KDniao.service.logistics.LogisticTrackingTrajectoryService;

/**
 * 物流跟踪信息Controller
 * @author OWEN
 * @version 2017-04-07
 */
@Controller
@RequestMapping(value = "${adminPath}/logistic_tracking_trajectory/logisticTrackingTrajectory")
public class LogisticTrackingTrajectoryController extends BaseController {

	@Autowired
	private LogisticTrackingTrajectoryService logisticTrackingTrajectoryService;
	@ModelAttribute
	public LogisticTrackingTrajectory get(@RequestParam(required=false) String id) {
		LogisticTrackingTrajectory entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = logisticTrackingTrajectoryService.get(id);
		}
		if (entity == null){
			entity = new LogisticTrackingTrajectory();
		}
		return entity;
	}
	
	@RequiresPermissions("logistic_tracking_trajectory:logisticTrackingTrajectory:view")
	@RequestMapping(value = {"list", ""})
	public String list(LogisticTrackingTrajectory logisticTrackingTrajectory, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<LogisticTrackingTrajectory> page = logisticTrackingTrajectoryService.findPage(new Page<LogisticTrackingTrajectory>(request, response), logisticTrackingTrajectory); 
		model.addAttribute("page", page);
		return "modules/logistic_tracking_trajectory/logisticTrackingTrajectoryList";
	}

	@RequiresPermissions("logistic_tracking_trajectory:logisticTrackingTrajectory:view")
	@RequestMapping(value = "form")
	public String form(LogisticTrackingTrajectory logisticTrackingTrajectory, Model model) {
		model.addAttribute("logisticTrackingTrajectory", logisticTrackingTrajectory);
		return "modules/logistic_tracking_trajectory/logisticTrackingTrajectoryForm";
	}

	@RequiresPermissions("logistic_tracking_trajectory:logisticTrackingTrajectory:edit")
	@RequestMapping(value = "save")
	public String save(LogisticTrackingTrajectory logisticTrackingTrajectory, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, logisticTrackingTrajectory)){
			return form(logisticTrackingTrajectory, model);
		}
		logisticTrackingTrajectoryService.save(logisticTrackingTrajectory);
		addMessage(redirectAttributes, "保存轨迹跟踪成功");
		return "redirect:"+Global.getAdminPath()+"/logistic_tracking_trajectory/logisticTrackingTrajectory/?repage";
	}
	
	@RequiresPermissions("logistic_tracking_trajectory:logisticTrackingTrajectory:edit")
	@RequestMapping(value = "delete")
	public String delete(LogisticTrackingTrajectory logisticTrackingTrajectory, RedirectAttributes redirectAttributes) {
		logisticTrackingTrajectoryService.delete(logisticTrackingTrajectory);
		addMessage(redirectAttributes, "删除轨迹跟踪成功");
		return "redirect:"+Global.getAdminPath()+"/logistic_tracking_trajectory/logisticTrackingTrajectory/?repage";
	}

    /***
     * 根据订单查询物流轨迹
     * 
     * @param ordercode订单信息
     * @return
     */
    @RequestMapping(value = "=logisticTrackingTrajectory")
    public Object getinfo(String ordercode) {
        if (ordercode == null || "".equals(ordercode)) {
            return null;
        }
        LogisticTrackingTrajectory logisticTrackingTrajectory = logisticTrackingTrajectoryService.getTrackingTrajectorybyOrderCode(ordercode);
        //ObjectMapper mapper = new ObjectMapper();
        String str = logisticTrackingTrajectory.getDatas();
        return str;
    }

}